package com.app.coderead;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.servlet.http.*;

import com.jdo.Employee;
import com.sys.Pmf;

@SuppressWarnings("serial")
public class DemoDataStore extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        String TAG = this.getClass().getName();
        Logger log = Logger.getLogger(TAG);
        
        
        //get PersistenceManager instance
        PersistenceManagerFactory pmf = Pmf.get();
        PersistenceManager pm = pmf.getPersistenceManager();
        
        //data object
        Employee e = new Employee("xxx", "xxx", new Date());
        
        try {
            //insert
            pm.makePersistent(e);
        } finally {
            pm.close();
        }
        //after pm.close
        pm = pmf.getPersistenceManager();
        
        //Selected by SQL string
        String query = "select from " + Employee.class.getName() + " where lastName == 'xxx'";
        List<Employee> employees = (List<Employee>) pm.newQuery(query).execute();
        log.info("employees.size() : " + employees.size());
    }
}
